package com.example.myapplication.tack_17.adappter;

import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;

import com.example.myapplication.tack_17.LuXianActivity;
import com.example.myapplication.tack_17.data.RotueData02;
import com.example.myapplication.tack_17.data.RouteData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;


public class RouteAdapter extends RecyclerView.Adapter<RouteAdapter.My> {
    private List<RouteData.RowsDTO> list;
    private Context context;
    private View view;

    public RouteAdapter(List<RouteData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.tack_17_route,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {

        holder.name.setText(list.get(position).getName());
        holder.first.setText("起点:"+list.get(position).getFirst());
        holder.end.setText("终点:"+list.get(position).getEnd());
        holder.mileage.setText("里程:"+list.get(position).getMileage()+"公里");
        holder.price.setText("票价:"+list.get(position).getPrice()+"元");
        holder.line.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, LuXianActivity.class);
                intent.putExtra(Common.COMMON,String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });

    }



    @Override
    public int getItemCount() {
        return list != null?list.size():0;
    }

    public class My extends RecyclerView.ViewHolder{
        private TextView name;
        private TextView first;
        private TextView end;
        private TextView mileage;
        private TextView price;
        private LinearLayout line;
        public My(@NonNull View itemView) {
            super(itemView);
            name = view.findViewById(R.id.name);
            first = view.findViewById(R.id.first);
            end = view.findViewById(R.id.end);
            mileage = view.findViewById(R.id.mileage);
            price = view.findViewById(R.id.price);
            line = view.findViewById(R.id.line);
        }
    }
}
